Please follow these steps before or soon after the first lecture.
Install the following software. If you already have R/RStudio installed, please re-install both.
We now describe how to install R packages, or extensions to R, from the CRAN repository of packages.
ggplot2 dplyr to install both those packages.library(ggplot2) and library(dplyr) and ensure the resulting messages does not contain any errors.RStudio is an integrated development environment that acts as a user interface for R.
In R Studio there are (by default) four “panes” to work in.
These can all be configured, but we’ll stick with the default configuration for now.
R studio Screenshot
The Source Pane provides several helpful features:
The console “is” R. You feed commands into it, and it produces output. It also keeps track of variables, functions, etc. that you define, and the previous commands you’ve given.
The console pane is where you directly interact with the console. You can do this by typing commands in directly, or by running them from the source pane.
The output from the console is often given in the console. Plots appear separately (by default in the “Plots/Help” pane).
You can view a few different things in the upper right. By default you’ll see the Environment, where R shows you what things it’s keeping track of (Data frames, variables, functions). Many of these things, e.g. data frames and functions, can be opened in the source pane for viewing.
You can also view the commands the console has run, in the order it ran them.
Plots is self-explanatory. Note that you can flip back and forth between various plots you’ve made.
The Help browser allows you to search for documentation on functions you are using, or might use. You can also access these from the console. Great when you know roughly what you want to do, but need to check syntax. Also, check the “See Also” at the bottom if you’re not sure what function you’re looking for.
You can install packages from the Packages tab by clicking Install and the name of the package you are trying to install. _Note: Packages must be loaded via library() command to be able to use the package. for eg.
library(cars)
To see them all, press alt+shift+k.
It is good practice to change your working directory in R to the folder you want to read files from and write files to. This can be accomplished in RStudio in two different ways:
Notice that if you chose to perform the first option above, RStudio automatically types the second option out for you in the console.
You can find out what your working directory is at any point by typing
getwd()
in the R console.
In RMarkdown there are three different content:
R Markdown
Untitled1 should pop-up.summary(cars) in the first code block to print("Hello world!")helloworld.RmdAn HTML/PDF document should pop-up in the Viewer tab.
qplotqplot Function Arguments